package com.android.slide;

import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;

import com.android.slide.databinding.FragmentMainBinding;

import java.util.ArrayList;
import java.util.List;

/**
 * FileName: MainFragment
 * Author: admin
 * Date: 2021/12/1 16:41
 * Description:
 */
public class MainFragment extends Fragment {

    private static final String TYPE_TITLE = "type_title";
    private FragmentMainBinding mainBinding;
    private MainAdapter mainAdapter;
    private int typeTitle = 0;

    public static MainFragment createFragment(int type) {
        MainFragment childFragment = new MainFragment();
        Bundle bundle = new Bundle();
        bundle.putInt(TYPE_TITLE, type);
        childFragment.setArguments(bundle);
        return childFragment;
    }

    @Nullable
    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        mainBinding = FragmentMainBinding.inflate(inflater);
        return mainBinding.getRoot();
    }

    @Override
    public void onActivityCreated(@Nullable @org.jetbrains.annotations.Nullable Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);
        typeTitle = getArguments().getInt(TYPE_TITLE);
        mainAdapter = new MainAdapter();
        mainBinding.recyclerView.setAdapter(mainAdapter);
        mainAdapter.setList(getList());
    }

    private List<String> getList() {
        List<String> list = new ArrayList<>();
        for (int index = 0; index < 50; index++) {
            if(typeTitle == 0){
                list.add("Android" + index);
            }
            if(typeTitle == 1){
                list.add("Java" + index);
            }
            if(typeTitle == 2){
                list.add("HTML" + index);
            }
            if(typeTitle == 3){
                list.add("Python" + index);
            }
            if(typeTitle == 4){
                list.add("C++" + index);
            }
        }
        return list;
    }

}
